<?php

/**
 * Admin_Modul_Rule Model
 * 
 * Short file description
 *
 * PHP Version: 5.3.26
 * 
 * @category Admin_Modul_Rule_Models
 * @package  Admin_Modul_Rule_Package
 * @author   
 * @license  
 * @link     
 */

namespace Admin\Models\Modul;

use \Laravel\Database\Eloquent\Model as Eloquent;
use Datagrid;
use Admin\Models\Modul\Step;
use Laravel\Config;

/**
 * Class Admin_Modul_Rule Model
 * 
 * Class Description
 *
 * @category Admin_Modul_Rule_Models
 * @package  Admin_Modul_Rule_Package
 * @author   
 * @license  Laravel License
 * @link     
 */

class Rule extends Eloquent 
{

	public static $timestamps = true;
    public static $table = 'sys_flow_rule';
    public static $key = 'sfr_id';

	/**
     * Function listSteps that pass parameter
     *
     * @param integer $flowid the integer to quote
	 *
	 * @return parameter.
     */
    public static function listRule($flowid)
	{
        $stepRule = Rule::where('sys_flow_rule.sf_id', '=', $flowid)
        			->left_join('sys_flow_step as c','c.sfs_id','=','sys_flow_rule.sfs_id')
        			->left_join('sys_flow_step as n','n.sfs_id','=','sys_flow_rule.sfr_next')
        			->left_join('sys_user_role as sur','sur.sur_id','=','sys_flow_rule.sur_id')
        			->left_join('sys_modul_page as smp','smp.smp_id','=','sys_flow_rule.sfr_page')
        			->paginate(
        				Config::get('system.pagination'),
        				array('smp.smp_action_alias','sur.sur_name','c.sfs_step as current','n.sfs_step as next','sys_flow_rule.*')
        			);

        $datagrid = new Datagrid;
        $datagrid->setFields(array('current' => 'Current Step'));
        $datagrid->setFields(array('next' => 'Next Step'));
        $datagrid->setFields(array('sur_name' => 'Auth Role'));
        $datagrid->setFields(array('smp_action_alias' => 'Page'));
        $datagrid->setFields(array('sfr_state' => 'State'));
        $datagrid->setAction('edit', 'editRule', true, array(static::$key));
        $datagrid->setAction('delete', 'deleteRule', true, array(static::$key));
        $datagrid->setTable('rule', 'table table-bordered table-hover table-striped table-condensed');
        $datagrid->build($stepRule, static::$key);

        return $datagrid->render();
    }


}
